﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DrugStorehouseMIS.DAL;
using DrugStorehouseMIS.Comm;
using DrugStorehouseMIS.DAL.Interface;


namespace DrugStorehouseMIS.BLL
{
    public class Inventory
    {
        #region 封装属性

        private int mID;

        public int ID
        {
            get { return mID; }
            set { mID = value; }
        }

        private Drug mDrugNum;

        public Drug DrugNum
        {
            get { return mDrugNum; }
            set { mDrugNum = value; }
        }

        private int mStockQuantity;

        public int StockQuantity
        {
            get { return mStockQuantity; }
            set { mStockQuantity = value; }
        }


        //private int mInventoryNum;

        //public int InventoryNum
        //{
        //    get { return mInventoryNum; }
        //    set { mInventoryNum = value; }
        //}

        //private Drug mDrugName;

        //public Drug DrugName
        //{
        //    get { return mDrugName; }
        //    set { mDrugName = value; }
        //}

        //private int mStockQuantity;

        //public int StockQuantity
        //{
        //    get { return mStockQuantity; }
        //    set { mStockQuantity = value; }
        //}

        //private string mBatchNum;

        //public string BatchNum
        //{
        //    get { return mBatchNum; }
        //    set { mBatchNum = value; }
        //}

        //private string mStockInNum;

        //public string StockInNum
        //{
        //    get { return mStockInNum; }
        //    set { mStockInNum = value; }
        //}

        //private DateTime mStockInDatetime;

        //public DateTime StockInDatetime
        //{
        //    get { return mStockInDatetime; }
        //    set { mStockInDatetime = value; }
        //}

        //private DateTime mExpiryDatetime; //有效日期

        //public DateTime ExpiryDatetime
        //{
        //    get { return mExpiryDatetime; }
        //    set { mExpiryDatetime = value; }
        //}

        //private float mTradePrice; //批发价

        //public float TradePrice
        //{
        //    get { return mTradePrice; }
        //    set { mTradePrice = value; }
        //}

        //private float mRetailPrice; //零售价

        //public float RetailPrice
        //{
        //    get { return mRetailPrice; }
        //    set { mRetailPrice = value; }
        //}

        //private float mImportPrice;   //进货价

        //public float ImportPrice
        //{
        //    get { return mImportPrice; }
        //    set { mImportPrice = value; }
        //}

        #endregion

        private IInventoryDAL dal;

        public Inventory()
        {
            dal=Adapter.GetInventory();
        }

        public void FetchObject(IDataReader dr)
        {
            if (dr != null)
            {
                mID = ConvertDataType.CheckFiledInt(dr["ID"]);
                mDrugNum.DrugNum = ConvertDataType.CheckFiledInt(dr["drug_num"]);
                mStockQuantity = ConvertDataType.CheckFiledInt(dr["stock_quantity"]);           
            }
        }

        public int GetStockQuantity(int DrugNum)
        {
            return dal.Select(DrugNum);
        }

        //public bool Insert(Inventory inventory)
        //{

        //    //return dal.Insert( inventory.DrugName.TradeName,inventory.StockQuantity, inventory.BatchNum, inventory.StockInNum, inventory.StockInDatetime, inventory.ExpiryDatetime, inventory.TradePrice, inventory.RetailPrice, inventory.ImportPrice) > 0 ? true : false;
        //}



        public bool AddInventory(Inventory inventory)
        {
            return dal.Add(inventory.DrugNum.DrugNum, inventory.StockQuantity) > 0 ? true : false;
           
        }


        public bool CutInventory(Inventory inventory)
        {
            return dal.Cut(inventory.DrugNum.DrugNum, inventory.StockQuantity) > 0 ? true : false;
        }
    }
}
